//同时发送异步代码的次数
let ajaxTimes = 0;
export const request = (params) => {
    ajaxTimes++;
    // 显示加载中样式
    wx.showLoading({
        title: "加载中",
        mask: true,
    });
    let header = {...params.header };
    header["token"] = wx.getStorageSync("token");
    // // 定义公共的url
    // const baseUrl = "http://47.111.119.98:8085/";
    const baseUrl = "https://www.xiantaoyuan0318.cn/";

    // const baseUrl = "http://192.168.0.164:8085/";

    return new Promise((resolve, reject) => {
        wx.request({
            ...params,
            header: header,
            url: baseUrl + params.url,
            method: "POST",
            //成功后调用
            success: (result) => {
                resolve(result.data);
            },
            // 失败后调用
            fail: (err) => {
                reject(err);
            },
            // 不管成功失败后都调用
            complete: () => {
                ajaxTimes--;
                if (ajaxTimes === 0) {
                    wx.hideLoading();
                }
            },
        });
    });
};